﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;
using DataAccessLayer;

namespace ServiceLayer.Entity
{
    [DataContract]
    public class PurchaseOrderW
    {
        int pOID;
        string requestedDate;
        string expectedDeliveryDate;
        string supplierID;
        int attn;
        int requestedBy;
        string approvalDate;
        int approvalBy;
        string status;
        string deliveryDate;
        string deliveryOrderNo;
        string reason;

        [DataMember]
        public int POID
        {
            get { return pOID; }
            set { pOID = value; }
        }

        [DataMember]
        public string RequestedDate
        {
            get { return requestedDate; }
            set { requestedDate = value; }
        }

        [DataMember]
        public string ExpectedDeliveryDate
        {
            get { return expectedDeliveryDate; }
            set { expectedDeliveryDate = value; }
        }

        [DataMember]
        public string SupplierID
        {
            get { return supplierID; }
            set { supplierID = value; }
        }

        [DataMember]
        public int Attn
        {
            get { return attn; }
            set { attn = value; }
        }

        [DataMember]
        public int RequestedBy
        {
            get { return requestedBy; }
            set { requestedBy = value; }
        }

        [DataMember]
        public string ApprovalDate
        {
            get { return approvalDate; }
            set { approvalDate = value; }
        }

        [DataMember]
        public int ApprovalBy
        {
            get { return approvalBy; }
            set { approvalBy = value; }
        }

        [DataMember]
        public string Status
        {
            get { return status; }
            set { status = value; }
        }

        [DataMember]
        public string DeliveryDate
        {
            get { return deliveryDate; }
            set { deliveryDate = value; }
        }

        [DataMember]
        public string DeliveryOrderNo
        {
            get { return deliveryOrderNo; }
            set { deliveryOrderNo = value; }
        }

        [DataMember]
        public string Reason
        {
            get { return reason; }
            set { reason = value; }
        }
        public static PurchaseOrderW convert(PurchaseOrder purchaseOrder)
        {
            PurchaseOrderW u = new PurchaseOrderW();

            u.POID = purchaseOrder.POID;
            u.RequestedDate = purchaseOrder.RequestedDate.GetValueOrDefault().ToString();
            u.ExpectedDeliveryDate = purchaseOrder.ExpectedDeliveryDate.GetValueOrDefault().ToString();
            u.SupplierID = purchaseOrder.SupplierID;
            u.Attn = purchaseOrder.Attn.GetValueOrDefault();
            u.RequestedBy = purchaseOrder.RequestedBy.GetValueOrDefault();
            u.ApprovalDate = purchaseOrder.ApprovalDate.GetValueOrDefault().ToString();
            u.ApprovalBy = purchaseOrder.ApprovalBy.GetValueOrDefault();
            u.Status = purchaseOrder.Status;
            u.DeliveryDate = purchaseOrder.DeliveryDate.GetValueOrDefault().ToString();
            u.DeliveryOrderNo = purchaseOrder.DeliveryOrderNo;
            u.Reason = purchaseOrder.Reason;
            return u;
        }

        public static List<PurchaseOrderW> convertList(List<PurchaseOrder> list)
        {
            List<PurchaseOrderW> listW = new List<PurchaseOrderW>();

            foreach (PurchaseOrder x in list)
            {
                listW.Add(convert(x));
            }
            return listW;
        }
    }
}